package com.example.shengyin.service;

import com.example.shengyin.dao.CommentMapper;
import com.example.shengyin.entity.Comment;
import com.example.shengyin.entity.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentService {

    @Autowired
    private CommentMapper dao;

    public int userInsert(Comment comment) {
        return dao.userInsert(comment);
    }

    public List<Comment> comNum(Long articleid) {
        return dao.comNum(articleid);
    }

    // 返回文章id的所有评论的数量
    public Long countByarticleid(@Param("articleid") Long articleid){
        return dao.countByarticleid(articleid);
    }

    public List<Comment> list(Page page, @Param("starttime") Date starttime, @Param("endtime") Date endtime,String uname) {
        return dao.list((page.getPage() - 1) * page.getLimit(), page.getLimit(), starttime, endtime,uname);
    }

    public int count( Date starttime, Date endtime,@Param("uname")String uname)
    {
        return dao.count(starttime,endtime,uname);
    }


    public int update(Comment comment) {
        return dao.update(comment);
    }


    public int delete(@Param("id") Long id) {
        return dao.delete(id);
    }

    // 根据评论id查它的userid
    public Long selectUseridById(@Param("id")Long id){
        return dao.selectUseridById(id);
    }

    public int deleteByIds(@Param("ids") String ids){
        return dao.deleteByIds(ids);
    }
}
